//package com.qianyu.core.config;
//
//import com.qianyu.core.util.MqUtil;
//import org.apache.activemq.ActiveMQConnectionFactory;
//import org.apache.activemq.command.ActiveMQQueue;
//import org.apache.activemq.command.ActiveMQTopic;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.env.Environment;
//import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
//import org.springframework.jms.config.JmsListenerContainerFactory;
//import org.springframework.jms.config.SimpleJmsListenerContainerFactory;
//import org.springframework.jms.core.JmsMessagingTemplate;
//import org.springframework.jms.core.JmsTemplate;
//
//import javax.jms.ConnectionFactory;
//import javax.jms.Queue;
//import javax.jms.Topic;
//
//@Configuration
//public class ActiveMqConfig {
//
//    @Autowired
//    private Environment env;
//    @Bean
//    ConnectionFactory connectionFactory() {
//        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
//        connectionFactory.setBrokerURL(env.getProperty("spring.activemq.broker-url"));
//        connectionFactory.setUserName(env.getProperty("spring.activemq.user"));
//        connectionFactory.setPassword(env.getProperty("spring.activemq.password"));
//        return connectionFactory;
//    }
//
//    @Bean
//    JmsTemplate jmsTemplate(ConnectionFactory connectionFactory) {
//        JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
//        jmsTemplate.setDefaultDestination(queue());
//        jmsTemplate.setPriority(999);
//        return jmsTemplate;
//    }
//
////    @Bean(value="jmsMessagingTemplate")
////    JmsMessagingTemplate jmsMessagingTemplate(JmsTemplate jmsTemplate) {
////        JmsMessagingTemplate messagingTemplate = new JmsMessagingTemplate(jmsTemplate);
////        return messagingTemplate;
////    }
//    // 在Queue模式中，对消息的监听需要对containerFactory进行配置
//    /**
//     * 实现监听queue
//     */
//    @Bean("jmsQueueListenerContainerFactory")
//    public JmsListenerContainerFactory<?> queueContainerFactory(ConnectionFactory connectionFactory){
//        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
//        factory.setConnectionFactory(connectionFactory);
//        //开启接收topic类型的消息
//        factory.setPubSubDomain(false);
//        return factory;
//    }
//
//    //在Topic模式中，对消息的监听需要对containerFactory进行配置
////    @Bean("topicListener")
////    public JmsListenerContainerFactory<?> topicJmsListenerContainerFactory(ConnectionFactory connectionFactory){
////        SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
////        factory.setConnectionFactory(connectionFactory);
////        factory.setPubSubDomain(true);
////        return factory;
////    }
////
//    /**
//     * 队列名称
//     */
//    @Bean
//    public Queue queue() {
//        return new ActiveMQQueue(MqUtil.qqAccountQueue) ;
//    }
//
////    /**
////     * 队列名称
////     */
////    @Bean
////    public Topic topic() {
////        return new ActiveMQTopic(MqUtil.topicName) ;
////    }
//}
